package com.handpay.nocardpay.baselibrary.account.presenter;

import android.content.Context;

import com.handpay.nocardpay.baselibrary.account.model.IModifyUserInfoModel;
import com.handpay.nocardpay.baselibrary.account.model.impl.ModifyUserInfoModelImpl;
import com.handpay.nocardpay.baselibrary.account.view.ImodifyUserInfoView;
import com.handpay.nocardpay.baselibrary.commbase.model.IBaseModel;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseErrorInfo;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseResponseBean;
import com.handpay.nocardpay.baselibrary.commbase.presenter.IBasePresenter;

import java.util.HashMap;

/**
 * Created by sxshi on 2017/8/17.
 */

public class ModifyUserinfoPresenterImpl implements IBasePresenter {
    private Context mContext;
    private ImodifyUserInfoView userInfoView;
    private IModifyUserInfoModel<BaseResponseBean> modifyPhoneModel;

    public void setUserInfoView(ImodifyUserInfoView userInfoView) {
        this.userInfoView = userInfoView;
    }

    public ModifyUserinfoPresenterImpl(Context mContext) {
        this.mContext = mContext;
        modifyPhoneModel = new ModifyUserInfoModelImpl(mContext);
    }

    /**
     * 检测手机号码是否合法
     *
     * @param paramers
     * @param isShowLoading
     */
    public void checkPhoneNumber(HashMap<String, Object> paramers, boolean isShowLoading) {
        if (userInfoView != null) {
            if (isShowLoading) {
                userInfoView.showProgress();
            }
        }
        modifyPhoneModel.checkPhoneNumber(paramers, BaseResponseBean.class, new IBaseModel.OnRequestFinishedListener<BaseResponseBean>() {
            @Override
            public void onError(BaseErrorInfo baseErrorInfo) {
                if (userInfoView != null) {
                    userInfoView.hideProgress();
                    userInfoView.showErrorAlert(baseErrorInfo);
                }
            }

            @Override
            public void onSuccess(BaseResponseBean response) {
                if (userInfoView != null) {
                    userInfoView.hideProgress();
                    userInfoView.modifyUserInfoFinsh();
                }
            }
        });
    }

    /**
     * 修改手机号码
     *
     * @param paramers
     * @param isShowLoading
     */
    public void modifyPhoneNumber(HashMap<String, Object> paramers, boolean isShowLoading) {
        if (userInfoView != null) {
            if (isShowLoading) {
                userInfoView.showProgress();
            }
        }
        modifyPhoneModel.modifyPhoneNumber(paramers, BaseResponseBean.class, new IBaseModel.OnRequestFinishedListener<BaseResponseBean>() {
            @Override
            public void onError(BaseErrorInfo baseErrorInfo) {
                if (userInfoView != null) {
                    userInfoView.hideProgress();
                    userInfoView.showErrorAlert(baseErrorInfo);
                }
            }

            @Override
            public void onSuccess(BaseResponseBean response) {
                if (userInfoView != null) {
                    userInfoView.hideProgress();
                    userInfoView.modifyUserInfoFinsh();
                }
            }
        });
    }

    /**
     * 修改登录密码
     *
     * @param paramers
     * @param isShowLoading
     */
    public void modifyLoginPwd(HashMap<String, Object> paramers, boolean isShowLoading) {
        if (userInfoView != null) {
            if (isShowLoading) {
                userInfoView.showProgress();
            }
        }
        modifyPhoneModel.modifyAccountLoginPwd(paramers, BaseResponseBean.class, new IBaseModel.OnRequestFinishedListener<BaseResponseBean>() {
            @Override
            public void onError(BaseErrorInfo baseErrorInfo) {
                if (userInfoView != null) {
                    userInfoView.hideProgress();
                    userInfoView.showErrorAlert(baseErrorInfo);
                }
            }

            @Override
            public void onSuccess(BaseResponseBean response) {
                if (userInfoView != null) {
                    userInfoView.hideProgress();
                    userInfoView.modifyUserInfoFinsh();
                }
            }
        });
    }

    /**
     * 修改收款卡信息
     *
     * @param paramers
     * @param isShowLoading
     */
    public void modifyAccountBankInfo(HashMap<String, Object> paramers, boolean isShowLoading) {
        if (userInfoView != null) {
            if (isShowLoading) {
                userInfoView.showProgress();
            }
        }
        modifyPhoneModel.modifyAccountBankInfo(paramers, BaseResponseBean.class, new IBaseModel.OnRequestFinishedListener<BaseResponseBean>() {
            @Override
            public void onError(BaseErrorInfo baseErrorInfo) {
                if (userInfoView != null) {
                    userInfoView.hideProgress();
                    userInfoView.showErrorAlert(baseErrorInfo);
                }
            }

            @Override
            public void onSuccess(BaseResponseBean response) {
                if (userInfoView != null) {
                    userInfoView.hideProgress();
                    userInfoView.modifyUserInfoFinsh();
                }
            }
        });
    }

    @Override
    public void onDestory() {
        if (userInfoView != null)
            userInfoView = null;
    }
}
